#include"../../commom/message.hpp"
#include"../../commom/dispatcher.hpp"
#include"../../commom/net.hpp"
void onRpcRequest(const rpc::BaseConnection::ptr &conn,const rpc::BaseMessage::ptr &msg)
{
    std::cout<<"收到了rpc请求"<<std::endl;
    std::string s=msg->serialize();
    std::cout<<s<<std::endl;
    auto rpc_req=rpc::MessageFactory::create<rpc::RpcResponse>();
    rpc_req->setId(msg->id());
    rpc_req->setMType(rpc::MType::RSP_RPC);
    rpc_req->setRcode(rpc::RCode::RCODE_OK);
    rpc_req->setResult(33);
    conn->send(rpc_req);
}
int main()
{
    auto dispatcher=std::make_shared<rpc::Dispatcher>();
    dispatcher->registerHandler<rpc::RpcRequest>(rpc::MType::REQ_RPC,onRpcRequest);
    auto message_cb=std::bind(&rpc::Dispatcher::onMessage,dispatcher.get(),
            std::placeholders::_1,std::placeholders::_2); 
    auto server=rpc::ServerFactory::create(8080);
    server->setMessageCallback(message_cb);
    server->start();
    
}